local skel = fk.CreateSkill {
  name = "emo__huiye",
}

Fk:loadTranslationTable{
  ["emo__huiye"] = "辉曳",
  [":emo__huiye"] = "每回合结束时，若你手牌均为红色/黑色，你可以令一名角色获得弃牌堆的“荧”/“惑”，若不为你，你摸两张牌。",

  ["#emo__huiye-choose"] = "辉曳：你可以令一名角色获得“%arg”，若不为你，你摸两张牌",
}

skel:addEffect(fk.TurnEnd, {
  anim_type = "drawcard",
  can_trigger = function (self, event, target, player, data)
    if not player:hasSkill(skel.name) then return false end
    local hand, mark = player:getCardIds("h"), nil
    if #hand == 0 then return false end
    for _, id in ipairs(hand) do
      local color = Fk:getCardById(id).color
      if color == Card.NoColor then return false end
      if mark == nil then
        mark = color
      elseif mark ~= color then
        return false
      end
    end
    mark = mark == Card.Red and "@@emo__bright" or "@@emo__confuse"
    local cards = table.filter(player.room.discard_pile, function (id)
      return Fk:getCardById(id):getMark(mark) ~= 0
    end)
    if #cards > 0 then
      event:setCostData(self, {cards = cards, mark = mark })
      return true
    end
  end,
  on_cost = function (self, event, target, player, data)
    local cost_cata = event:getCostData(self)
    local tos = player.room:askToChoosePlayers(player, {
      min_num = 1, max_num = 1, targets = player.room.alive_players, skill_name = skel.name,
      prompt = "#emo__huiye-choose:::" .. cost_cata.mark ,
    })
    if #tos > 0 then
      cost_cata.tos = tos
      event:setCostData(self, cost_cata)
      return true
    end
  end,
  on_use = function (self, event, target, player, data)
    local room = player.room
    local to = event:getCostData(self).tos[1]
    local cards = event:getCostData(self).cards
    room:obtainCard(to, cards, true, fk.ReasonPrey, player, skel.name)
    if to ~= player and player:isAlive() then
      player:drawCards(2, skel.name)
    end
  end,
})

return skel
